package Server.players;

import Server.map.Box;


public class Carnivorous extends Dino{

	public static final int MAX_DISTANCE = 3;
	public Carnivorous(int id){
		super(id);
	}
	public Carnivorous(int id, Box location){
		super(id, location);
	}
	public Carnivorous(Carnivorous c){
		super(c);
	}
	@Override
	public boolean equals(Object b) {
		if (b instanceof Carnivorous){
			Carnivorous c = (Carnivorous) b;
			if (this.idDino.equals((c.idDino)))
					return true;
		}
		return false;
	}
	@Override
	public int hashCode(){
		return 31 * this.idDino.hashCode();
	}
	@Override
	public boolean isCarniv() {
		return true;
	}
	@Override
	public boolean isHerb() {
		return false;
	}
	@Override
	public int maxDistance(){
		return Carnivorous.MAX_DISTANCE;
	}
	
	/*
	 * @requires foodBox != null
	 * @ensures foodBox.isMeatBox() <==> this.getEnergy() >= \old(this.getEnergy()
	 */
	@Override
	public void eat(Box foodBox) {
		if (foodBox.isMeatBox()){
			if (this.energy + foodBox.getFoodEnergy() > 1000 * this.dimension)
				this.energy = 1000 * this.dimension;
			else this.energy += foodBox.getFoodEnergy();
		}
	}
	
	/* 
	 * @requires d != null
	 * @ensures (\result == this || \result == d) &&
	 * (* this più forte di d *) => this.getEnergy == \old(this.getEnergy) + 0.75 * d.getEnergy
	 */
	@Override
	public Dino fight(Dino d) {
		int myForce = 2 * this.energy * this.dimension;
		int hisForce;
		if (d instanceof Carnivorous)
			hisForce = 2 * d.energy * d.dimension;
		else hisForce = d.energy * d.dimension;
		
		if (myForce >= hisForce){
			this.energy += (int)(0.75 * d.energy);
			return this;
		} 

		d.energy += (int)(0.75 * this.energy);
		return d;

	}

	

}